How to convert Bitmap to byte[,,] faster?

Posted by Miko Kronn on Stack Overflow See other posts from Stack Overflow or by Miko Kronn
Published on 2011-01-12T21:35:42Z Indexed on 2011/01/12 21:53 UTC
Read the original article Hit count: 161

Filed under:
|
|
|

I wrote function:

    public static byte[, ,] Bitmap2Byte(Bitmap image)
    {
        int h = image.Height;
        int w = image.Width;

        byte[, ,] result= new byte[w, h, 3];

        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < h; j++)
            {
                Color c= image.GetPixel(i, j);
                result[i, j, 0] = c.R;
                result[i, j, 1] = c.G;
                result[i, j, 2] = c.B;
            }
        }

        return result;
    }

But it takes almost 6 seconds to convert 1800x1800 image. Can I do this faster?

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms